package top.xizai.anti.replay;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

/**
 * @NAME: WSC
 * @DATE: 2021/12/17
 * @DESCRIBE:
 **/
public class TAntiReplayAttack {

    @Test
    public void rsaTest() {
        RSA rsa = new RSA();

        String publicKey = rsa.getPublicKeyBase64();
        String privateKey = rsa.getPrivateKeyBase64();

        System.out.println(publicKey);
        System.out.println(privateKey);

        var rsa2 = new RSA(null, publicKey);
        var encrypt = rsa2.encrypt("hello world", KeyType.PublicKey);

        var rsa1 = new RSA(privateKey, null);
        var ret = StrUtil.str(rsa1.decrypt(encrypt, KeyType.PrivateKey), StandardCharsets.UTF_8);
        System.out.println(ret);
    }
}
